package com.ruoyi.cencat.mapper;

import com.ruoyi.common.myconmon.Result;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface CencatGetDataMapper {

    @Select("SELECT COUNT(*) AS totalSupplierCount FROM cencat_supplier")
    int getTotalSupplierCount();

    @Select("SELECT COUNT(*) AS totalCustomerCount FROM cencat_customer")
    int getTotalCustomerCount();

    @Select("SELECT COUNT(*) AS totalGoodsCount FROM cencat_goods")
    int getTotalGoodsCount();

    @Select("SELECT SUM(record_number) AS totalInboundCount FROM cencat_record_in")
    int getTotalInboundCount();

    @Select("SELECT SUM(record_number) AS totalOutboundCount FROM cencat_record_out")
    int getTotalOutboundCount();

    @Select("SELECT (in_records.in_total - out_records.out_total) / #{totalCapacity} AS warehouseUtilizationRate " +
            "FROM (SELECT SUM(record_number) AS in_total FROM cencat_record_in) AS in_records " +
            "JOIN (SELECT SUM(record_number) AS out_total FROM cencat_record_out) AS out_records")
    double getWarehouseUtilizationRate(int totalCapacity);

    @Select("SELECT record_time, record_person, '入库' AS type FROM cencat_record_in " +
            "UNION " +
            "SELECT record_time, record_person, '出库' AS type FROM cencat_record_out " +
            "ORDER BY record_time DESC LIMIT 1")
    List<Map<String, Object>> getRecentOperations();
}
